feat(transport): Add EnvelopePrinterTransport for debug logging#6181
feat(transport): Add EnvelopePrinterTransport for debug logging#6181ericapisani wants to merge 8 commits intomasterfrom
Conversation
Add a decorator transport that logs envelope contents via the SDK debug logger before forwarding to the inner transport. Activated by setting SENTRY_PRINT_ENVELOPES=1|true|yes. Includes tests for delegation, logging behavior, make_transport integration, and strict env var parsing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 7.38s All tests are passing successfully. ❌ Patch coverage is 46.00%. Project has 14962 uncovered lines. Files with missing lines (1)
Generated by Codecov Action |
|
bugbot run |
|
@sentry review |
…sport coverage - Override __class__ to delegate to inner transport so isinstance checks (e.g. AsyncHttpTransport) remain transparent - Add __getattr__ fallback for attributes not explicitly defined - Return values from flush() and kill() so async tasks propagate - Wrap transport in all make_transport paths (pre-instantiated, callable) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
bugbot run |
|
@sentry review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit f050b85. Configure here.
…ry/sentry-python into envelope-printer-transport-zcgvd
| def __init__(self, transport: "Transport") -> None: | ||
| Transport.__init__(self, options=transport.options) | ||
| self._inner = transport | ||
| self.parsed_dsn = transport.parsed_dsn |
There was a problem hiding this comment.
Bug: A KeyError can occur in _EnvelopePrinterTransport when wrapping a custom transport that has a non-empty options dictionary without a "dsn" key.
Severity: LOW
Suggested Fix
In Transport.__init__, modify the condition to safely check for the existence of the "dsn" key before accessing it, for example, by using options.get("dsn") or "dsn" in options.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: sentry_sdk/transport.py#L1089-L1092
Potential issue: The `_EnvelopePrinterTransport` wraps a given transport and calls the
base `Transport.__init__` with the inner transport's `options`. The base `__init__`
method then executes `if options and options["dsn"]`. If a user provides a custom
transport with a non-empty `options` dictionary that lacks a `"dsn"` key, this check
will raise a `KeyError`. This bug is triggered when the `SENTRY_PRINT_ENVELOPES=1`
environment variable is set and a pre-instantiated custom transport is used.
Adds
EnvelopePrinterTransport, a decorator transport that wraps the real transport and pretty-prints each envelope's headers and item payloads to the SDK debug logger before forwarding the envelope.Enabled via
SENTRY_PRINT_ENVELOPES=1(also acceptstrue/yes). When unset or falsy, no wrapping occurs and there's no runtime cost. Useful for local debugging without having to run a local Sentry instance or intercept network traffic.Fixes PY-2398
Fixes #6183